# encoding: utf-8
""" 
@version: v1.0 
@author: autumner 
@license: Apache Licence  
@contact: 18322313385@163.com 
@site:  https://gitee.com/autumner/pythoncookbook
@software: PyCharm 
@file: net_ssl_flask_client.py 
@time: 2019/7/17 上午9:19
"""
'''
单向认证客户端
'''
import urllib.request
import ssl


if __name__ == '__main__':
    CA_FILE = 'server_cert.pem'


    context = ssl.SSLContext(ssl.PROTOCOL_TLS)
    context.check_hostname = False
    context.load_verify_locations(CA_FILE)
    context.verify_mode = ssl.CERT_REQUIRED
    try:
        req = urllib.request.Request('https://127.0.0.1:5000/')
        res = urllib.request.urlopen(req, context=context)
        print(res.code)
        print(res.read().decode('utf-8'))
    except Exception as ex:
        print('Found Error in auth phase:%s' % str(ex))

